﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class Locations
    {
        public static readonly String ElementName = "Locations";

        private Collection<Location> _Locations = new Collection<Location>();
        public IEnumerable<Location> LocationList
        {
            get { foreach (var item in _Locations) { yield return item; } }
        }

        public Locations(XElement xml)
        {
            IEnumerable<XElement> els;
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*Locations*/
            els = xml.ElementsByLocalName(Location.ElementName);
            foreach (var item in els)
            {
                var add = new Location(item);
                this._Locations.Add(add);
            }
        }
    }

    public class Location
    {
        public static readonly String ElementName = "Location";

        public String Name { get; private set; }
        public String DisplayName { get; private set; }

        public Location(XElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*Location*/
            this.Name = xml.ValueOrEmpty("Name");
            this.DisplayName = xml.ValueOrEmpty("DisplayName");
        }
    }
}
